/**
 * Created by Freeman on 2017/3/16.
 */
import Vue from 'vue';
import Vuex from 'vuex';
import utils from '../commons/utils';
import * as types from './types';
import * as getters from './getters';
import * as actions from './actions';
import user from './modules/user_modules';
import header from './modules/header_modules';
Vue.use(Vuex);

// global state
const state = {
  isLoading: false,
  direction: '',
  isTip: false,
  tipText: '默认提示信息',
  chooseClass: '',
  chooseSchool: '',
  chooseId: '',
  currClass: {},              // 当前选择的班级

  // 确认对话框配置
  confirmConfig: {
    show: false,            // 是否显示对话框
    title: '',              // 对话框标题
    content: '',            // 对话框内容
    leftBtnText: '',        // 左边按我导文本
    leftBtnEvent: null,     // 左边按钮事件
    rightBtnText: '',       // 右边按钮文本
    rightBtnEvent: null,    // 右边按钮事件
  },

  weChatInitd: false          // 微信SDK初始化状态
};
const mutations = {
  [types.UPDATE_LOADING] (state, status) {
    state.isLoading = status
  },
  [types.UPDATE_TIP](state, tipText) {
    state.isTip = !!tipText
    if (state.isTip) {
      state.tipText = tipText
    }
  },
  [types.UPDATE_DIRECTION] (state, direction) {
    state.direction = direction
  },
  [types.UPDATE_CONFIRM](state, confirmConfig) {
    if (confirmConfig) {
      Object.assign(state.confirmConfig, confirmConfig)
    } else {
      utils.resetObject(state.confirmConfig)
    }
  },
};


const store = new Vuex.Store({
  state,
  actions,
  getters,
  mutations,
  modules: {
    user,
    header,
  },
  strict: process.env.NODE_ENV !== 'production'
})

export default store;
